﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using MediaData;

namespace MediaData
{
    public abstract class MediaItemScanner
    {
        public string Type { get; set; }
        public List<string> VideoExtensions { get; private set; }
        public List<string> DiscImageExtensions { get; private set; }

        public MediaItemScanner(string name)
        {
            this.Type = name;
            VideoExtensions = new List<string>(MediaUtil.BasicVideoExtensions);
            DiscImageExtensions = new List<string>(MediaUtil.BasicDiscImageExtensions);
        }

        public abstract void Scan(MediaRoot root, Predicate<MediaItem> exists, Action<MediaItem> mediaAdded);

        protected MediaType GetType(string filename)
        {
            filename = filename.ToLower();
            string fext = Path.GetExtension(filename);
            if (fext.Length == 0)
                return MediaType.Unknown;
            fext = fext.Substring(1);

            if (VideoExtensions.Contains(fext))
                return MediaType.Video;

            if (DiscImageExtensions.Contains(fext))
                return MediaType.DiscImage;

            return MediaType.Unknown;
        }
        protected enum MediaType
        {
            Video,
            DiscImage,
            Unknown
        }
    }
}
